package com.tadpole.music.holder.study;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.study.ExaminationErrorListBean;
import com.tadpole.music.config.UrlConfig;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.utils.ToastUtils;
import com.tadpole.music.view.activity.study.ErrorQuestionActivity;
import com.tadpole.music.view.activity.study.ExaminationErrorActivity;
import com.tadpole.music.view.widget.LollipopFixedWebView;

import java.util.List;

/**
 * Created By 孙岩
 * on 2020/10/10
 */
public class ExaminationErrorViewHolder extends BaseViewHolder {
    private View itemView;
    private BaseAdapter.OnItemClickListener onItemClickListener;
    private BaseAdapter.OnChildClickListener onChildClickListener;
    private List<ExaminationErrorListBean.DataBeanX.DataBean> list;
    private LollipopFixedWebView tvTitle;
    private Activity activity;
    //查看错题
    private TextView tvSeeError;
    //重新做题
    private TextView tvSelect;
    private String flag;
    public ExaminationErrorViewHolder(Activity activity,View itemView, BaseAdapter.OnItemClickListener onItemClickListener,BaseAdapter.OnChildClickListener onChildClickListener, List<ExaminationErrorListBean.DataBeanX.DataBean> list,String flag) {
        super(itemView);
        this.activity = activity;
        this.onItemClickListener = onItemClickListener;
        this.itemView = itemView;
        this.list = list;
        this.onChildClickListener = onChildClickListener;
        this.flag = flag;

    }

    @Override
    public void init(final int position) {
        tvTitle = itemView.findViewById(R.id.tvTitle);
        tvSeeError = itemView.findViewById(R.id.tvSeeError);
        tvSelect = itemView.findViewById(R.id.tvSelect);
        String url = UrlConfig.getTitle + "q_type=question&id=" + list.get(position).getId();
        tvTitle.loadUrl(url);
        tvTitle.getSettings().setNeedInitialFocus(false);

        if("1".equals(flag)){
            tvSelect.setVisibility(View.VISIBLE);
        }else if("2".equals(flag)){
            tvSelect.setVisibility(View.GONE);
        }

        tvSeeError.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onChildClickListener.onChildClick(tvSeeError,position);
            }
        });

        tvSelect.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onChildClickListener.onChildClick(tvSelect,position);
            }
        });

    }
}
